#include "../mqserver/mq_message.hpp"
#include <gtest/gtest.h>

ljhmq::MessageManager::ptr mmp;

class MessageTest : public testing::Environment {
    public:
        virtual void SetUp() override {
            mmp = std::make_shared<ljhmq::MessageManager>("./data/message/");
            mmp->initQueueMessage("queue1");
        }
        virtual void TearDown() override {
            //mmp->clear();
        }
};

//新增消息测试

TEST(message_test, insert_test) {
    ljhmq::BasicProperties properties;
    properties.set_id(ljhmq::UUIDHelper::uuid());
    properties.set_delivery_mode(ljhmq::DeliveryMode::DURABLE);
    properties.set_routing_key("news.music.pop");
    mmp->insert("queue1", &properties, "Hello World-1",ljhmq::DeliveryMode::DURABLE);
    mmp->insert("queue1", nullptr, "Hello World-2", ljhmq::DeliveryMode::DURABLE);
    mmp->insert("queue1", nullptr, "Hello World-3",ljhmq::DeliveryMode::DURABLE);
    mmp->insert("queue1", nullptr, "Hello World-4", ljhmq::DeliveryMode::DURABLE);
    mmp->insert("queue1", nullptr, "Hello World-5", ljhmq::DeliveryMode::UNDRABLE);
    ASSERT_EQ(mmp->getable_count("queue1"), 5);
    ASSERT_EQ(mmp->total_count("queue1"), 4);
    ASSERT_EQ(mmp->durable_count("queue1"), 4);
    ASSERT_EQ(mmp->waitack_count("queue1"), 0);
}

int main(int argc,char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MessageTest);
    RUN_ALL_TESTS();
    return 0;
}